extends MoveStateResource


class_name CurveStateResource


enum Mode {
    Sin,
    Cos,
}

## 移动模式
@export var mode: Mode = Mode.Sin
## 曲线半径
@export var radius: float = 50
## 移动的初始角度
@export_range(0, 180, 1, "radians") var angle: float = deg_to_rad(90)


func enter(ctrl: MoveController, data: Dictionary) -> void:
    data.start_direction = ctrl.move_component.direction

func update(ctrl: MoveController, data: Dictionary, delta: float, duration: float) -> bool:
    var angle_increment: float = (radius * 7.64) / ctrl.move_component.speed
    # 重新计算偏移角度
    angle = wrapf(angle + angle_increment * delta, 0, TAU)
    var curve: float = 1.0
    match mode:
        Mode.Sin:
            curve = sin(angle)
        Mode.Cos:
            curve = cos(angle)
    ctrl.move_component.direction = (data.start_direction.orthogonal() * curve + data.start_direction).normalized()
    return false
